# T2I version 0.22, copyright (C) Santeri Piippo 2007

# GLBOAL VARIABLES
# $conns	- connections (server => chid)
# $RECV_LISTEN	- the [recv] "listen" array: defines handler commands for
#	messages. Basically a module registration array ;)
# $UHOSTS	- an userhost container
# $IMAGES	- an image container, see gui.tcl for usage
# $CONFIG - array used for configuration, use [saveconfig] if you want
#	to save changes to $CONFIG

package require starkit
package require Tk
package require dns
package require tls

starkit::startup

namespace import msgcat::mc msgcat::mcset msgcat::mclocale

set TTKSTYLE "ttk::style"
if { [package vcompare [package provide Tcl] 8.5] < 0 } {
	package require tile
	set TTKSTYLE "style"
}

set NAMESLOCK 0
set VERSION 0.23

array set conns {}
array set RECV_LISTEN {}
array set UHOSTS {}
array set IMAGES {}
array set LANGS {}

# Load (or create if needed) the config file
source [file join $starkit::topdir config.tcl]

# Get identifiers
source [file join $starkit::topdir po langs.tcl]

set CONFIGFILE "~/.t2i-rc"
if ![file exists $CONFIGFILE] {
	createconfig
}

# Load the configuration file (see config.tcl
# to see what specifically happens)
loadconfig

# Load the configuration into variables
set FONT	$CONFIG(defaultfont)
set LI  	$CONFIG(lang)

if {[info exists CONFIG(nick)] == 0} {
	set CONFIG(nick) {}
	set CONFIG(ident) {}
	set CONFIG(realname) {}
	saveconfig
}

$TTKSTYLE theme use $CONFIG(widgetstyle)

# Load the language used. English is used in arguments
# of [tr], so if the language is english, we don't need
# to load any external files
if {$LI != "en"} {
	source [file join $starkit::topdir po $LI.tcl]
	mclocale $LI
}

# [source] all module files
foreach file [glob -directory [file join $starkit::topdir mod] *] {
	source $file
}

# [source] all the program files.
set FILES {tr
	about chfont chlang chstyle connect createnetwork
	dns f_output gui list maskhost output parsenicklist
	recv send util}

foreach file $FILES {
	source [file join $starkit::topdir $file.tcl]
}
